/*
 * @Description: 
 * @Version: 0.1
 * @Autor: Civet
 * @Date: 2019-08-02 16:04:58
 * @LastEditors: Civet
 * @LastEditTime: 2019-09-09 10:02:02
 */

import Vue from 'vue'
import Router from 'vue-router'
// import templateFile from '@/components/templateFile' // 模板页
// import test from '@/views/test'
import {Message} from 'element-ui';

import login from '@/views/login/loginLogic' // 登录
import frame from '@/views/frame/frameView'
import frameWork from '@/views/frameWork'

import homeView from '@/views/home/homeView' // 主页

import notFound from '@/views/404.vue';


let session = window.sessionStorage;


Vue.use(Router);

const frameChildren = [
  {
    name: 'homeView',
    path: 'home',
    component: homeView,
  }
];


const router = new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      name: 'login',
      component: login,
    },
    {
      path: '/frame',
      component: frame,
      redirect: '/frame/home',
      meta: {
        requiresAuth: true// 说明需要鉴权
      },
      children: frameChildren
    },
    {
      path: '/frameWork',
      component: frameWork,
      redirect: '/frameWork/home',
      meta: {
        requiresAuth: true// 说明需要鉴权
      },
      children: frameChildren
    },
    {path: '*', name: 'noFound', component: notFound}
  ]
})


// 全局守卫  https://router.vuejs.org/zh-cn/advanced/navigation-guards.html
router.beforeEach((to, from, next) => {
  // 获得那些路由需要token验证
  // console.log("to", to);
  // console.log("from", from);
  // console.log("next", next);
  // let userData = JSON.parse(session.getItem('userData'));
  // if (to.path == "/" && userData) {
  //   next('/frame/policeInfo');
  // } else if (to.matched.some(route => route.meta.requiresAuth)) {
  //   console.log("userData", userData);
  //   if (userData) {
  //     next();
  //   } else {
  //     // 没有登录的提示
  //     Message.error('您还没有登录');
  //     next('/');
  //   }
  // } else {
  //   next(); // 确保一定要调用
  // }
  next();
});

export default router;
